package org.jsola.hr.helper;

import org.jsola.hr.dto.CrmCustomerDistributionRecordAddDTO;
import org.jsola.hr.dto.CrmCustomerDistributionRecordUpdateDTO;
import org.jsola.hr.entity.CrmCustomerDistributionRecordDO;
import org.jsola.hr.query.CrmCustomerDistributionRecordQuery;
import org.jsola.hr.service.ICrmCustomerDistributionRecordService;
import org.jsola.hr.vo.CrmCustomerDistributionRecordVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 客户分配记录表
 *
 * @author zhr
 */
@Component
public class CrmCustomerDistributionRecordTestHelper extends BaseTestHelper {
    
    @Autowired
    private ICrmCustomerDistributionRecordService crmCustomerDistributionRecordService;

    /**
     * 生成add测试数据
     * @return CrmCustomerDistributionRecordAddDTO
     */
    public CrmCustomerDistributionRecordAddDTO getCrmCustomerDistributionRecordAddDTO(){
        CrmCustomerDistributionRecordAddDTO crmCustomerDistributionRecordAddDTO = new CrmCustomerDistributionRecordAddDTO();
        crmCustomerDistributionRecordAddDTO.setCustomerId(getRandomValue("varchar",32));
        crmCustomerDistributionRecordAddDTO.setDistributionInfo(getRandomValue("varchar",100));
        crmCustomerDistributionRecordAddDTO.setDistributionReason(getRandomValue("varchar",100));
        return crmCustomerDistributionRecordAddDTO;
    }


    /**
     * 生成update测试数据
     * @return CrmCustomerDistributionRecordUpdateDTO
     */
    public CrmCustomerDistributionRecordUpdateDTO getCrmCustomerDistributionRecordUpdateDTO(CrmCustomerDistributionRecordVO crmCustomerDistributionRecordVO){
        return crmCustomerDistributionRecordService.selectDOById(crmCustomerDistributionRecordVO.getId(), SITE_ID).to(CrmCustomerDistributionRecordUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return CrmCustomerDistributionRecordQuery
     */
    public CrmCustomerDistributionRecordQuery getCrmCustomerDistributionRecordQuery() {
        CrmCustomerDistributionRecordQuery crmCustomerDistributionRecordQuery = new CrmCustomerDistributionRecordQuery();
        List<CrmCustomerDistributionRecordDO> crmCustomerDistributionRecordDOList = crmCustomerDistributionRecordService.list(new CrmCustomerDistributionRecordDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(crmCustomerDistributionRecordDOList)) {
            CrmCustomerDistributionRecordDO crmCustomerDistributionRecordDO = crmCustomerDistributionRecordDOList.get(0);
            crmCustomerDistributionRecordQuery = crmCustomerDistributionRecordDO.to(CrmCustomerDistributionRecordQuery.class);
        }
        return crmCustomerDistributionRecordQuery;
    }

    /**
     * 保存示例
     * @return CrmCustomerDistributionRecordVO
     */
    public CrmCustomerDistributionRecordVO saveCrmCustomerDistributionRecordExample(){
        CrmCustomerDistributionRecordAddDTO addDTO = this.getCrmCustomerDistributionRecordAddDTO();
        CrmCustomerDistributionRecordVO crmCustomerDistributionRecordVO = crmCustomerDistributionRecordService.save(addDTO,buildTokenUser());
        return crmCustomerDistributionRecordVO;
    }


}

